package com.jiacl.service.impl;

import com.jiacl.core.CommonConstants.ErrorCode;
import com.jiacl.entity.JiaclFamilyTree;
import com.jiacl.entity.core.Result;
import com.jiacl.exception.BusinessException;
import com.jiacl.mapper.JiaclFamilyTreeMapper;
import com.jiacl.service.FamilyTreeService;
import com.jiacl.utils.Utils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Date;

/**
 * Created by XiaoWei on 2017/10/19.
 */
@Service
public class FamilyTreeServiceImpl implements FamilyTreeService {
    @Resource
    private JiaclFamilyTreeMapper jiaclFamilyTreeMapper;
    @Override
    public Result addFamilyTree(JiaclFamilyTree jiaclFamilyTree) {
        if(StringUtils.isEmpty(jiaclFamilyTree.getUserId())){
            throw new BusinessException(ErrorCode.ERROR_ILLEGAL_USER);//userId为空
        }
        if(StringUtils.isEmpty(jiaclFamilyTree.getSurnameId())){
            throw new BusinessException(ErrorCode.ERROR_SENIORITY_ERROR); //姓氏为空
        }
        jiaclFamilyTree.setCreateBy(jiaclFamilyTree.getUserId());
        jiaclFamilyTree.setCreateTime(new Date());
        jiaclFamilyTreeMapper.insertSelective(jiaclFamilyTree);
        return new Result();
    }
}
